package cn.jhc.servlet;

import cn.jhc.db.SurveyItemDao;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.sql.Connection;

@WebServlet("/delete.do")
public class DeleteItemServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String sid = req.getParameter("id");
        int id = Integer.parseInt(sid);
        Connection connection = (Connection) req.getServletContext().getAttribute("connection");
        SurveyItemDao.delete(connection, id);
        resp.sendRedirect("list.jsp");
    }
}
